<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core">

    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputText value="#{bundle.AppName}"></h:outputText>
        </ui:define>
        <ui:define name="body">
            <h:form>
                <p:panel header="#{bundle.MessageTitlePanelLeft}" style="width: 20%;float: left; " >
                    <h:panelGrid columns="1" style="width: 100%">
                        <h:outputLabel value="Chats Recientes"/>   
                        <p:selectOneListbox  id="currentsChats" value="#{messagesBean.userSelected}" style="width: 100%;" converter="#{usuarioConverter}" > 
                            <f:selectItems value="#{messagesBean.getChatsUsers()}" var="user2" itemValue="#{user2}" itemLabel="#{user2.nombre}"/>
                            <f:converter binding="#{usuarioConverter}"/>
                            <p:ajax update="chatPanel"/>
                        </p:selectOneListbox>
                        <h:outputLabel value="#{bundle.Autocomplete}"/>                        
                        <p:autoComplete value="#{messagesBean.userSelected}" completeMethod="#{messagesBean.completeUser}" var="user" itemLabel="#{user.nombre}" itemValue="#{user}" converter="#{usuarioConverter}" maxResults="10" minQueryLength="2" forceSelection="true" effect="puff" style="width: 100px;float: left" >  
                            <p:column>  
                                <p:graphicImage value="resources/images/profiles/#{loginBean.user.fotoUrl}" width="40" height="40"/>  
                            </p:column>
                            <p:column >  
                                #{user.nombre}
                            </p:column>  
                            <p:ajax update="chatPanel" event="itemSelect"/>
                        </p:autoComplete>
                        <h:outputLabel value="#{bundle.SubjectOfSemester}" for="subjectList"/>
                        <p:selectOneListbox id="subjectList" value="#{messagesBean.subjectSelected}" style="width: 100%" immediate="true"> 
                            <f:selectItems value="#{messagesBean.subjectsUser}" var="subject" itemValue="#{subject}" itemLabel="#{subject.nombre} - Sec.#{subject.seccion} "/>                   
                            <f:converter binding="#{asignaturaConverter}"/>
                            <p:ajax update="studentsList"/>
                        </p:selectOneListbox>

                        <h:outputLabel value="#{bundle.MessageTitleListUsers}"/>
                        <p:selectOneListbox  id="studentsList" widgetVar="studentsList" value="#{messagesBean.userSelected}" style="width: 100%;" converter="#{usuarioConverter}" > 
                            <f:selectItems value="#{messagesBean.usersSubject}" var="user" itemValue="#{user}" itemLabel="#{user.nombre}"/>
                            <f:converter binding="#{usuarioConverter}"/>
                            <p:ajax update="chatPanel"/>
                        </p:selectOneListbox>
                    </h:panelGrid>
                </p:panel>
                <p:panel id="chatPanel" header="#{bundle.MessageTitleChatPanel} #{messagesBean.userSelected.nombre}" style="width: 78%;float: left;">
                    <c:forEach items="#{messagesBean.getAllMessageUSer()}" var="message">
                        <c:if test="#{messagesBean.validateMessage(message.idusuario.idusuario)}" >
                            <p:panel style="text-align: right">
                                <h:outputText value="#{bundle.MessageIam} " style="font-weight: bold;"/>
                                <h:outputText value="#{message.mensaje}" escape="false"/>
                                <h:outputText value="#{message.fecha}" escape="false" style="float: left"/>
                            </p:panel>
                        </c:if>
                        <c:if test="#{message.idusuario.idusuario != loginBean.user.idusuario}">
                            <p:panel  styleClass="ui-state-hover" style="text-align: left;">
                                <h:outputText value="#{messagesBean.userSelected.nombre} #{bundle.MessageTitleTalk} " style="font-weight: bold;" />
                                <h:outputText value="#{message.mensaje}" escape="false" />
                                 <h:outputText value="#{message.fecha}" escape="false" style="float: right"/>
                            </p:panel> 
                        </c:if>
                    </c:forEach>
                    <p:inputTextarea value="#{messagesBean.selected.mensaje}" style="width: 88%;float: left" maxlength="100">
                        <p:ajax update="chatPanel currentsChats" event="blur" />
                    </p:inputTextarea>
                    <p:commandButton update="chatPanel currentsChats" actionListener="#{messagesBean.send(event)}" value="#{bundle.MessageTitleButtonSend}" style="width:10%; height: 50px; float: right"/>

                </p:panel>
            </h:form>
        </ui:define>

    </ui:composition>

</html>


